package com.chenglai.goods.controller;

import com.chenglai.commonutils.common.Result;
import com.chenglai.commonutils.common.StatusCode;
import com.chenglai.goods.pojo.GoodsSpec;
import com.chenglai.goods.service.GoodsSpecService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * 类描述：
 *
 * @Author rxh
 * @Date 2023/11/17 9:46
 */
@RestController
@RequestMapping("/goodsSpec/")
public class GoodsSpecController {

    @Resource
    private GoodsSpecService goodsParamService;

    /**
     * 获取商品规格列表
     *
     * @param page   页码
     * @param size   数量
     * @param shopId 门店id
     * @return
     */
    @PostMapping("getGoodsSpecList")
    @ApiOperation(value = "获取商品规格列表")
    public Result getGoodsSpecList(@ApiParam(name = "page", value = "页码") Integer page,
                                    @ApiParam(name = "size", value = "数量") Integer size,
                                    @ApiParam(name = "shopId", value = "门店ID") Integer shopId) {
        try {
            PageInfo pageInfo = goodsParamService.getGoodsSpecList(page, size, shopId);
            return new Result(true, StatusCode.OK, "操作成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 添加/修改商品规格
     *
     * @param goodsSpec 商品规格实体类
     */
    @PostMapping("editGoodsSpec")
    @ApiOperation(value = "添加/修改商品规格")
    public Result editArticleCategory(GoodsSpec goodsSpec) {
        try {
            goodsParamService.editGoodsSpec(goodsSpec);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 删除商品规格
     *
     * @param specId 商品规格id
     */
    @PostMapping("delGoodsSpec")
    @ApiOperation(value = "删除商品规格")
    public Result delArticleCategory(@ApiParam(name = "specId", value = "商品规格ID") Integer specId) {
        try {
            goodsParamService.delGoodsSpec(specId);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 商品规格详情
     *
     * @param specId 商品规格id
     */
    @PostMapping("detail")
    @ApiOperation(value = "商品规格详情")
    public Result detail(@ApiParam(name = "specId", value = "商品规格ID") Integer specId) {
        try {
            GoodsSpec detail = goodsParamService.detail(specId);
            return new Result(true, StatusCode.OK, "查询成功", detail);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }
}
